//
//  HOTMineDetailTableViewCell.m
//  Genpara
//
//  Created by AndyChang.zhang on 14-9-15.
//  Copyright (c) 2014年 zhangchh. All rights reserved.
//

#import "HOTOrenoListCell.h"
#import "UIKit+AFNetworking.h"

@interface HOTOrenoListCell () {
    
    
}

@property(nonatomic,assign)float imageBtnHeight;
@end

@implementation HOTOrenoListCell

- (void)awakeFromNib
{
    // Initialization code
    
    NSArray *contraints = self.contentImageView.constraints;

    for (NSLayoutConstraint *con in contraints) {
        
        if (con.firstItem == self.contentImageView && con.firstAttribute == NSLayoutAttributeHeight) {
            
            self.imageBtnHeight = con.constant;
            break;
        }
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setContentImage:(NSURL *)url {
    
    if (url == nil) {

        NSArray *contraints = self.contentImageView.constraints;
        for (NSLayoutConstraint *con in contraints) {
            
            if (con.firstItem == self.contentImageView && con.firstAttribute == NSLayoutAttributeHeight) {
                
                con.constant = 0;
                break;
            }
        }
        
        [self.contentImageView setBackgroundImage:nil forState:UIControlStateNormal];
    } else {
        
            [self.contentImageView setBackgroundImageForState:UIControlStateNormal withURL:url];
        
        NSArray *contraints = self.contentImageView.constraints;
        for (NSLayoutConstraint *con in contraints) {
            
            if (con.firstItem == self.contentImageView && con.firstAttribute == NSLayoutAttributeHeight) {

                    con.constant = self.imageBtnHeight;

                
                break;
            }
        }

        //self.contentImageView.hidden = NO;

//        [self.contentImageView setBackgroundImageForState:UIControlStateNormal withURL:url];
//
        [self.contentImageView.superview setNeedsLayout];
        [self.contentImageView.superview setNeedsUpdateConstraints];
        [self.contentImageView setNeedsDisplay];
        [self.contentImageView setNeedsLayout];
        [self.contentImageView setNeedsUpdateConstraints];
        [self setNeedsDisplay];
        [self setNeedsUpdateConstraints];
        [self.contentView setNeedsDisplay];
        [self.contentView setNeedsUpdateConstraints];
    }
}

- (IBAction)contentImageClicked:(id)sender {
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(contentImageClicked:)]) {
        
        [self.delegate contentImageClicked:self.indexPath];
    }
}

@end
